package com.example.tourapp.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.example.tourapp.Pojo.Pojo_City;
import com.example.tourapp.R;
import com.example.tourapp.util.Util_Internet;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

public class Line_chart extends AppCompatActivity {

    private WebView web_view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_line_chart);
        EventBus.getDefault().register(this);
        initView();
        inifuction();
    }
    private void initView() {
        web_view = (WebView) findViewById(R.id.web_view);
    }
    private void inifuction() {

        web_view.getSettings().setJavaScriptEnabled(true);
        web_view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        web_view.addJavascriptInterface(this,"text");
        web_view.loadUrl("file:///android_asset/index.html");
        web_view.setWebChromeClient(new WebChromeClient()
        {
//            @Override
//            public void onProgressChanged(WebView view, int newProgress) {
//                super.onProgressChanged(view, newProgress);
//
//
//            }
        });
    }
    //获取前端传来的数据
    @JavascriptInterface
    public void web_text(String city)
    {
        Log.d("xx",city);
        Util_Internet.Get_ok(city,this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void text(String data)
    {
        web_view.loadUrl("javascript:t_json('"+data+"')");
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}